package com.hongxun.budget.ui.fragment.sg;

import android.widget.EditText;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.fragment.BaseFragment;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.budget.utils.SgDBUtils;
import com.hongxun.budget.utils.SgStrKey;
import com.hongxun.greenentity.sg.CBasicsWorkEntity;

import java.util.Date;

import butterknife.BindView;

/**
 * 隐蔽工程信息详情：设备基础
 */
public class EditBasicsWorkInfo extends BaseFragment {
    @BindView(R.id.et21)
    EditText et21;
    @BindView(R.id.et22)
    EditText et22;
    @BindView(R.id.et23)
    EditText et23;
    @BindView(R.id.et24)
    EditText et24;
    @BindView(R.id.et25)
    EditText et25;
    @BindView(R.id.et26)
    EditText et26;

    private CBasicsWorkEntity workEntity;

    public EditBasicsWorkInfo() {
    }

    @Override
    public int getLayoutId() {
        return R.layout.sg_fragment_editbasicsworkinfo;
    }

    @Override
    public void initView() {
        if (getArguments().getBoolean("isNewAdd", false)) {
            workEntity = new CBasicsWorkEntity();
            workEntity.setGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            workEntity.setPGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxm, "")));
            workEntity.setMCGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidjl, "")));
            workEntity.setBWDatastate("新增");
            workEntity.setBWResult("合格");
            //默认值
            et26.setText(workEntity.getBWResult());
        } else {
            workEntity = SgDBUtils.getCBasicsWork(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            et21.setText(workEntity.getBWContour());
            et22.setText(workEntity.getBWHigh());
            et23.setText(workEntity.getBWDig());
            et24.setText(workEntity.getBWDepth());
            et25.setText(workEntity.getBWGrade());
            et26.setText(workEntity.getBWResult());
        }
    }

    //保存
    public void saveData(String name) {
        String trim21 = et21.getText().toString().trim();
        String trim22 = et22.getText().toString().trim();
        String trim23 = et23.getText().toString().trim();
        String trim24 = et24.getText().toString().trim();
        String trim25 = et25.getText().toString().trim();
        String trim26 = et26.getText().toString().trim();

        workEntity.setMCName(name);
        workEntity.setBWContour(trim21);
        workEntity.setBWHigh(trim22);
        workEntity.setBWDig(trim23);
        workEntity.setBWDepth(trim24);
        workEntity.setBWGrade(trim25);
        workEntity.setBWResult(trim26);

        workEntity.setBWAddtime(new Date(System.currentTimeMillis()));
        SgDBUtils.upDataCBasicsWorkEntity(workEntity);
    }
}
